<?php

/**
 * This is the model class for table "{{reports}}".
 *
 * The followings are the available columns in table '{{reports}}':
 * @property integer $report_id
 * @property string $name
 * @property string $description
 * @property string $cdate
 * @property integer $org_id
 * @property integer $type
 * @property integer $rep_id
 * @property string $mail_subject
 * @property string $mail_body
 * @property string $ber_docName
 * @property integer $s_zyklus
 * @property integer $s_zyklus_gap
 * @property integer $s_zyklus_start
 * @property double $production_time
 * @property string $s_zyklus_time
 *
 * The followings are the available model relations:
 * @property Recipient[] $recipients
 * @property Weekdays[] $tblWeekdays
 */
class Reports extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Reports the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{reports}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('org_id, type, rep_id, s_zyklus, s_zyklus_gap, s_zyklus_start', 'numerical', 'integerOnly'=>true),
			array('production_time', 'numerical'),
			array('name, mail_subject', 'length', 'max'=>100),
			array('ber_docName', 'length', 'max'=>150),
			array('description, cdate, mail_body, s_zyklus_time', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('report_id, name, description, cdate, org_id, type, rep_id, mail_subject, mail_body, ber_docName, s_zyklus, s_zyklus_gap, s_zyklus_start, production_time, s_zyklus_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'recipients' => array(self::HAS_MANY, 'Recipient', 'report_id','together'=>true),
			'tblWeekdays' => array(self::MANY_MANY, 'Weekdays', '{{weekdays_has_tbl_reports}}(tbl_reports_report_id, tbl_weekdays_weekday_id)'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'report_id' => 'id',
			'name' => 'Report Name',
			'description' => 'Description',
			'cdate' => 'Created',
			'org_id' => 'Responsible',
			'type' => 'Type',
			'rep_id' => 'QV Report Id',
			'mail_subject' => 'Mail Subject',
			'mail_body' => 'Mail Body',
			'ber_docName' => 'QV Document',
			's_zyklus' => 'Cycle',
			's_zyklus_gap' => 'Cycle Gap',
			's_zyklus_start' => 'Cylcle Start',
			'production_time' => 'Production Time',
			's_zyklus_time' => 'Send Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('report_id',$this->report_id);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('cdate',$this->cdate,true);
		$criteria->compare('org_id',$this->org_id);
		$criteria->compare('type',$this->type);
		$criteria->compare('rep_id',$this->rep_id);
		$criteria->compare('mail_subject',$this->mail_subject,true);
		$criteria->compare('mail_body',$this->mail_body,true);
		$criteria->compare('ber_docName',$this->ber_docName,true);
		$criteria->compare('s_zyklus',$this->s_zyklus);
		$criteria->compare('s_zyklus_gap',$this->s_zyklus_gap);
		$criteria->compare('s_zyklus_start',$this->s_zyklus_start);
		$criteria->compare('production_time',$this->production_time);
		$criteria->compare('s_zyklus_time',$this->s_zyklus_time,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}